/*     */ package cn.com.hongpay.client.anal;
/*     */ 
/*     */ import cn.com.hongpay.client.vo.pay.SinglePayResVo;
/*     */ import cn.com.hongpay.client.vo.query.QueryResVo;
/*     */ import cn.com.hongpay.client.vo.refund.RefundResVo;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.InputStream;
/*     */ import java.text.SimpleDateFormat;
/*     */ import javax.xml.parsers.DocumentBuilder;
/*     */ import javax.xml.parsers.DocumentBuilderFactory;
/*     */ import org.w3c.dom.Document;
/*     */ import org.w3c.dom.Element;
/*     */ import org.w3c.dom.NodeList;
/*     */ 
/*     */ public class XmlAnalyze
/*     */ {
/*     */   protected SinglePayResVo getPayNotifyVo(String payNotifyXml)
/*     */     throws Exception
/*     */   {
/*  28 */     SinglePayResVo vo = new SinglePayResVo();
/*     */ 
/*  30 */     Element rootEle = getDocumentElement(payNotifyXml);
/*     */ 
/*  32 */     Element infoEle = getElementByName(rootEle, "INFO");
/*  33 */     vo.setPartnerId(getElementByName(infoEle, "PARTNER_ID").getTextContent());
/*  34 */     vo.setSignedMsg(getElementByName(infoEle, "SIGNED_MSG").getTextContent());
/*     */ 
/*  36 */     Element bodyEle = getElementByName(rootEle, "BODY");
/*  37 */     Element tradeDetails = getElementByName(bodyEle, "TRADE_DETAILS");
/*  38 */     Element transDetail = getElementByName(tradeDetails, "TRANS_DETAIL");
/*     */ 
/*  40 */     vo.setTradeNo(getElementByName(transDetail, "TRADE_NO").getTextContent());
/*  41 */     vo.setPartnerTradeNo(getElementByName(transDetail, "PARTNER_TRADE_NO").getTextContent());
/*  42 */     vo.setResultCode(getElementByName(transDetail, "RESULT_CODE").getTextContent());
/*  43 */     vo.setAmount(Long.valueOf(getElementByName(transDetail, "AMOUNT").getTextContent()).longValue());
/*  44 */     vo.setDetailRemark(getElementByName(transDetail, "DETAIL_REMARK").getTextContent());
/*  45 */     vo.setAcctReservedField1(getElementByName(transDetail, "ACCT_RESERVED_FIELD1").getTextContent());
/*  46 */     vo.setAcctReservedField2(getElementByName(transDetail, "ACCT_RESERVED_FIELD2").getTextContent());
/*  47 */     vo.setAcctReservedField3(getElementByName(transDetail, "ACCT_RESERVED_FIELD3").getTextContent());
/*     */ 
/*  49 */     return vo;
/*     */   }
/*     */ 
/*     */   protected QueryResVo getQueryResVo(String queryResXml) throws Exception
/*     */   {
/*  54 */     QueryResVo vo = new QueryResVo();
/*     */ 
/*  56 */     SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/*     */ 
/*  58 */     Element rootEle = getDocumentElement(queryResXml);
/*     */ 
/*  60 */     Element infoEle = getElementByName(rootEle, "INFO");
/*  61 */     vo.setPartnerId(getElementByName(infoEle, "PARTNER_ID").getTextContent());
/*  62 */     vo.setSignedMsg(getElementByName(infoEle, "SIGNED_MSG").getTextContent());
/*     */ 
/*  64 */     Element bodyEle = getElementByName(rootEle, "BODY");
/*  65 */     vo.setPartnerTradeNo(getElementByName(bodyEle, "PARTNER_TRADE_NO").getTextContent());
/*     */ 
/*  67 */     vo.setQueryTime(df.parse(getElementByName(bodyEle, "QUERY_TIME").getTextContent()));
/*  68 */     vo.setRetCode(getElementByName(bodyEle, "RET_CODE").getTextContent());
/*  69 */     vo.setRetMsg(getElementByName(bodyEle, "RET_MSG").getTextContent());
/*  70 */     vo.setQueryRemark(getElementByName(bodyEle, "QUERY_REMARK").getTextContent());
/*     */ 
/*  72 */     return vo;
/*     */   }
/*     */ 
/*     */   protected RefundResVo getRefundResVo(String refundResXml) throws Exception {
/*  76 */     RefundResVo vo = new RefundResVo();
/*     */ 
/*  78 */     SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/*     */ 
/*  80 */     Element rootEle = getDocumentElement(refundResXml);
/*     */ 
/*  82 */     Element infoEle = getElementByName(rootEle, "INFO");
/*  83 */     vo.setPartnerId(getElementByName(infoEle, "PARTNER_ID").getTextContent());
/*  84 */     vo.setSignedMsg(getElementByName(infoEle, "SIGNED_MSG").getTextContent());
/*     */ 
/*  86 */     Element bodyEle = getElementByName(rootEle, "BODY");
/*  87 */     vo.setPartnerTradeNo(getElementByName(bodyEle, "PARTNER_TRADE_NO").getTextContent());
/*  88 */     vo.setRefundAmount(Long.valueOf(getElementByName(bodyEle, "REFUND_AMOUNT").getTextContent()).longValue());
/*  89 */     vo.setRefundTime(df.parse(getElementByName(bodyEle, "REFUND_TIME").getTextContent()));
/*  90 */     vo.setRefundCode(getElementByName(bodyEle, "REFUND_CODE").getTextContent());
/*  91 */     vo.setRefundMsg(getElementByName(bodyEle, "REFUND_MSG").getTextContent());
/*  92 */     vo.setRefundRemark(getElementByName(bodyEle, "REFUND_REMARK").getTextContent());
/*     */ 
/*  94 */     return vo;
/*     */   }
/*     */ 
/*     */   private Element getDocumentElement(String xml) throws Exception {
/*  98 */     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
/*  99 */     DocumentBuilder db = dbf.newDocumentBuilder();
/*     */ 
/* 101 */     byte[] bytes = xml.getBytes("UTF-8");
/* 102 */     InputStream inps = new ByteArrayInputStream(bytes);
/*     */ 
/* 104 */     Document doc = db.parse(inps);
/* 105 */     Element rootEle = doc.getDocumentElement();
/*     */ 
/* 107 */     if (!"AIPAYTRADE".equalsIgnoreCase(rootEle.getNodeName())) {
/* 108 */       throw new Exception("报文错误,根节点不是:AIPAYTRADE");
/*     */     }
/*     */ 
/* 111 */     inps.close();
/*     */ 
/* 113 */     return rootEle;
/*     */   }
/*     */ 
/*     */   private Element getElementByName(Element pEle, String name) throws Exception {
/* 117 */     NodeList list = pEle.getElementsByTagName(name);
/* 118 */     if ((list != null) && (list.getLength() == 1)) {
/* 119 */       return (Element)list.item(0);
/*     */     }
/* 121 */     throw new Exception("报文错误，没有" + name + "节点或节点错误");
/*     */   }
/*     */ }

/* Location:           F:\hongpay_client.jar
 * Qualified Name:     cn.com.hongpay.client.anal.XmlAnalyze
 * JD-Core Version:    0.6.0
 */